package com.yljk.yljkproject.modelcallback;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.hyphenate.EMCallBack;
import com.hyphenate.chat.EMClient;
import com.yilijk.base.AppBase;
import com.yilijk.base.BaseApi;
import com.yilijk.base.constants.UserInfo;
import com.yilijk.base.network.RequestParams;
import com.yilijk.base.network.config.BaseRouter;
import com.yilijk.base.network.config.BaseUrl;
import com.yilijk.base.network.https.HttpCallBack;
import com.yilijk.base.network.https.HttpUtils;
import com.yilijk.base.network.https.NetAttestationUtils;
import com.yilijk.base.utils.ActivityManagerUtils;
import com.yilijk.base.utils.DevicesUtils;
import com.yilijk.base.utils.SharedPreferencesUtils;
import com.yilijk.base.view.LogoutDialog;
import com.yljk.live.common.utils.MediaCountyManager;
import com.yljk.mcconfig.constants.MCApi;
import com.yljk.servicemanager.constants.ConfigApi;
import com.yljk.servicemanager.constants.UrlApi;
import com.yljk.yljkproject.AppUrl;
import com.yljk.yljkproject.BuildConfig;
import com.yljk.yljkproject.MyApplication;
import com.yljk.yljkproject.ui.CenterActivity;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by SHICHENG
 * <p>
 * Time on 2022/03/08
 */
@Route(path = BaseRouter.Base)
public class BaseImpl implements BaseApi {
    @Override
    public boolean isOpenAttestation() {
        return ConfigApi.Open.isOpenAttestation;
    }

    @Override
    public boolean isOpenSendEvent() {
        return ConfigApi.Open.isOpenSendEvent;
    }

    @Override
    public String[] rnUpdataUrl() {
        return new String[]{
                "/api/app"
        };
    }

    @Override
    public int getDominNo() {
//        return BuildConfig.DOMIN_NO;
        return MyApplication.LocalDominNo;
    }

    @Override
    public String getDomin() {
//        return "https://apitest.yilijk.com";
        return MyApplication.LocalDominNo == 0 ? BaseUrl.DOMIN.d1 :
                MyApplication.LocalDominNo == 1 ? BaseUrl.DOMIN.t1 :
                        MyApplication.LocalDominNo == 2 ? "https://api.t2.yilijk.com" :
                                MyApplication.LocalDominNo == 3 ? BaseUrl.DOMIN.pre :
                                        BaseUrl.DOMIN.api;
    }

    @Override
    public String getWebUrl() {
        return MyApplication.LocalDominNo == 0 ? BaseUrl.WEB.d1 :
                MyApplication.LocalDominNo == 1 ? BaseUrl.WEB.t1 :
                        MyApplication.LocalDominNo == 2 ? BaseUrl.WEB.t1 :
                                MyApplication.LocalDominNo == 3 ? BaseUrl.WEB.pre :
                                        BaseUrl.WEB.api;
    }

    @Override
    public String getH5Url() {
        return MyApplication.LocalDominNo == 0 ? BaseUrl.H5.d1 :
                MyApplication.LocalDominNo == 1 ? BaseUrl.H5.t1 :
                        MyApplication.LocalDominNo == 2 ? BaseUrl.H5.t1 :
                                MyApplication.LocalDominNo == 3 ? BaseUrl.H5.pre :
                                        BaseUrl.H5.api;
    }

    @Override
    public String getPointUrl() {
        return MyApplication.LocalDominNo == 0 ? AppUrl.point_d1 :
                MyApplication.LocalDominNo == 1 ? AppUrl.point_t1 :
                        MyApplication.LocalDominNo == 2 ? AppUrl.point_t2 :
                                AppUrl.point_api;
    }

    @Override
    public String getOssPath() {
        return "doctor";
    }

    @Override
    public String getTerminal() {
        return "5";
    }

    @Override
    public String getApkType() {
        return BuildConfig.APK_TYPE;
    }

    @Override
    public void onCancelLogout(Activity activity) {
        if (activity == null) {
            activity = ActivityManagerUtils.getLastestActivity();
        }
        //删除本地
        //成功删除本地缓存数据
        boolean b = SharedPreferencesUtils.getInstance().removeAll(AppBase.getApplication());
        if (b) {
            NetAttestationUtils.getInstance().setSALT("");
            ActivityManagerUtils.finishAllActivity();
            Intent intent = new Intent(activity, CenterActivity.class);
            intent.putExtra("isLogout", true);
            activity.startActivity(intent);
            activity.finish();
        }
    }

    @Override
    public String[] noSign() {
        return new String[]{
                MCApi.Live.LIVE_SET_VIEWER_COUNT,
        };
    }

    @Override
    public boolean isEnvironment() {
        return MyApplication.LocalDominNo != 3 && MyApplication.LocalDominNo != 4;
    }

    @Override
    public boolean isOnline() {
        return MyApplication.LocalDominNo == 4;
    }

    @Override
    public RequestParams getClickParams(JSONObject jsonObject) {
        RequestParams params = new RequestParams();
        params.put("appId", 7);
        params.put("secretKey", "95f4ucv08u");
        params.put("terminal", DevicesUtils.getTerminal());
        try {
            jsonObject.put("visitid", SharedPreferencesUtils.getInstance().getString("visitid", null));
            jsonObject.put("uuid", SharedPreferencesUtils.getInstance().getString(UserInfo.openId, ""));
            jsonObject.put("passportId", SharedPreferencesUtils.getInstance().getString(UserInfo.passportId, ""));
        } catch (JSONException e) {
            e.printStackTrace();
        }
        params.put("log", jsonObject.toString());
        return params;
    }


    @Override
    public void init(Context context) {

    }

    @Override
    public boolean isUserAgreeChecked() {
        return MyApplication.getMyApplication().isUserAgreeChecked();
    }


}
